<?php

namespace Common\Models\Videos;

use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Uniqueness;
use Phalcon\Mvc\Model\Behavior\Timestampable;

class Video extends Model
{
    protected $id;

    protected $imdb;

    protected $national_id;

    protected $duration;

    protected $year_product;

    protected $year_publish;

    protected $is_vip;

    protected $hot_month;

    protected $total_view;

    protected $ip_address;

    protected $created_user;

    protected $published_user;

    protected $created_time;

    protected $updated_time;
    
    protected $status;

    public function getSource()
    {
        return 'video';
    }

    public function initialize()
    {
        $this->addBehavior(new Timestampable(array(
            'beforeValidationOnCreate' => array(
                'field' => 'created_at',
                'format' => 'Y-m-d H:i:s'
            ),
            'beforeValidationOnUpdate' => array(
                'field' => 'update_at',
                'format' => 'Y-m-d H:i:s'
            ),
        )));

        $this->setSource('video');

        $this->hasMany('id' , 'Common\Models\Videos\VideoFileLink' , 'video_id' , array(
            'alias' => 'videoFileLink'
        ));

        $this->hasOne('id' , 'Common\Models\Videos\VideoDescription' , 'video_id' , array(
            'alias' => 'videoDescription'
        ));

        $this->hasMany('id' , 'Common\Models\Videos\VideoCategoryLink' , 'video_id' , array(
            'alias' => 'videoCategoryLink'
        ));

        $this->hasMany('id' , 'Common\Models\Images\ImageLink' , 'object_id' , array(
            'alias' => 'imageLink'
        ));

        $this->hasOne('national_id' , 'Common\Models\Videos\National' , 'id' , array(
            'alias' => 'national'
        ));

    }

    /**
     * @return User
     */
    public static function findFirstById($parameters = array())
    {
        return parent::findFirstById($parameters);
    }

    /**
     * Validate that emails are unique across users
     */
    public function validation()
    {
        /*
        $this->validate(new Uniqueness(array(
            "field" => "email",
            "message" => "The email is already registered"
        )));

        return $this->validationHasFailed() != true;*/
    }

    public function beforeDelete()
    {
        $videoCategoryLink = VideoCategoryLink::find(array(
            "video_id = " . $this->id
        ));
        if($videoCategoryLink)
        {
            $videoCategoryLink->delete();
        }

        $videoDescription = VideoDescription::find(array(
            "video_id = " . $this->id
        ));
        if($videoDescription)
        {
            $videoDescription->delete();
        }

        $videoFileLink = VideoFileLink::find(array(
            "video_id = " . $this->id
        ));
        if($videoFileLink)
        {
            $videoFileLink->delete();
        }

        $videoGroupLink = VideoGroupLink::find(array(
            "video_id = " . $this->id
        ));
        if($videoGroupLink)
        {
            $videoGroupLink->delete();
        }

    }

    /**
     * @param mixed $imdb
     */
    public function setImdb($imdb)
    {
        $this->imdb = $imdb;
    }

    /**
     * @return mixed
     */
    public function getImdb()
    {
        return $this->imdb;
    }


    /**
     * @param mixed $created_time
     */
    public function setCreatedTime($created_time)
    {
        $this->created_time = $created_time;
    }

    /**
     * @return mixed
     */
    public function getCreatedTime()
    {
        return $this->created_time;
    }

    /**
     * @param mixed $created_user
     */
    public function setCreatedUser($created_user)
    {
        $this->created_user = $created_user;
    }

    /**
     * @return mixed
     */
    public function getCreatedUser()
    {
        return $this->created_user;
    }

    /**
     * @param mixed $duration
     */
    public function setDuration($duration)
    {
        $this->duration = $duration;
    }

    /**
     * @return mixed
     */
    public function getDuration()
    {
        return $this->duration;
    }

    /**
     * @param mixed $hot_month
     */
    public function setHotMonth($hot_month)
    {
        $this->hot_month = $hot_month;
    }

    /**
     * @return mixed
     */
    public function getHotMonth()
    {
        return $this->hot_month;
    }

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $ip_address
     */
    public function setIpAddress($ip_address)
    {
        $this->ip_address = $ip_address;
    }

    /**
     * @return mixed
     */
    public function getIpAddress()
    {
        return $this->ip_address;
    }

    /**
     * @param mixed $is_vip
     */
    public function setIsVip($is_vip)
    {
        $this->is_vip = $is_vip;
    }

    /**
     * @return mixed
     */
    public function getIsVip()
    {
        return $this->is_vip;
    }

    /**
     * @param mixed $national_id
     */
    public function setNationalId($national_id)
    {
        $this->national_id = $national_id;
    }

    /**
     * @return mixed
     */
    public function getNationalId()
    {
        return $this->national_id;
    }

    /**
     * @param mixed $published_user
     */
    public function setPublishedUser($published_user)
    {
        $this->published_user = $published_user;
    }

    /**
     * @return mixed
     */
    public function getPublishedUser()
    {
        return $this->published_user;
    }

    /**
     * @param mixed $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

    /**
     * @return mixed
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @param mixed $updated_time
     */
    public function setUpdatedTime($updated_time)
    {
        $this->updated_time = $updated_time;
    }

    /**
     * @return mixed
     */
    public function getUpdatedTime()
    {
        return $this->updated_time;
    }

    /**
     * @param mixed $total_view
     */
    public function setTotalView($total_view)
    {
        $this->total_view = $total_view;
    }

    /**
     * @return mixed
     */
    public function getTotalView()
    {
        return $this->total_view;
    }

    /**
     * @param mixed $year_product
     */
    public function setYearProduct($year_product)
    {
        $this->year_product = $year_product;
    }

    /**
     * @return mixed
     */
    public function getYearProduct()
    {
        return $this->year_product;
    }

    /**
     * @param mixed $year_publish
     */
    public function setYearPublish($year_publish)
    {
        $this->year_publish = $year_publish;
    }

    /**
     * @return mixed
     */
    public function getYearPublish()
    {
        return $this->year_publish;
    }    

}
